package cn.aws360.boot.base.api.exception;

import cn.aws360.boot.base.api.exception.enums.AbstractExceptionEnum;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author junnan
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 模块
     */
    private String module;

    /**
     * 错误码
     */
    private String errCode;

    /**
     * 用户提示
     */
    private String userTip;

    public ServiceException(String module, String errCode, String userTip) {
        super(userTip);
        this.module = module;
        this.errCode = errCode;
        this.userTip = userTip;
    }

    public ServiceException(AbstractExceptionEnum exceptionEnum) {
        super(exceptionEnum.getUserTip());
        this.module = exceptionEnum.getModule();
        this.errCode = exceptionEnum.getErrCode();
        this.userTip = exceptionEnum.getUserTip();
    }

    public ServiceException(AbstractExceptionEnum exceptionEnum, Object... tipParam) {
        super(exceptionEnum.getUserTip());
        this.module = exceptionEnum.getModule();
        this.errCode = exceptionEnum.getErrCode();
        this.userTip = StrUtil.format(exceptionEnum.getUserTip(), tipParam);
    }

}
